/**
 * ...
 * @author Franco Ponticelli
 */

package uform.model.cell;

import uform.model.core.Crawler;
import uform.model.core.Schema;
import uform.model.cell.ArrayCell;
import uform.model.value.StringType;
import utest.Assert;

class TestArrayCell extends Test
{
	public function testResolve()
	{
		var schema = new Schema();
		var pschema = new Schema();
		pschema.addCell("name",    new ValueCell(new StringType()));
		pschema.addCell("akas",    new ArrayCell(new StringType()));
		schema.addCell( "persons", new ArrayCell(pschema));
		
		var target : Dynamic = { };
		var crawler = new Crawler("persons", target);
		schema.resolve(crawler);
		Assert.isNull(crawler.get());
		crawler.set([]);
		Assert.same([], crawler.get());
		
		var crawler = new Crawler("persons[0]", target);
		schema.resolve(crawler);
		Assert.isNull(crawler.get());
		crawler.set({});
		Assert.same( { }, crawler.get());
		
		var crawler = new Crawler("persons[1].name", target);
		schema.resolve(crawler);
		Assert.isNull(crawler.get());
		crawler.set("franco");
		Assert.same("franco", crawler.get());
		
		var crawler = new Crawler("persons[1].akas[2]", target);
		schema.resolve(crawler);
		Assert.isNull(crawler.get());
		crawler.set("fponticelli");
		Assert.same("fponticelli", crawler.get());
		
		var crawler = new Crawler("persons[1].akas[1]", target);
		schema.resolve(crawler);
		Assert.isNull(crawler.get());
		crawler.set("franco.ponticelli");
		Assert.same("franco.ponticelli", crawler.get());
	}
	
	public function new();
}